package com.hxx.day7;

import org.junit.Test;

import java.util.*;

/**
 * 泛型
 */
public class TestDemo8 {
    /**
     * 泛型方法
     */
    @Test
    public void test01() {
        List<Integer> list = new ArrayList();
        list.add(100);
        list.add(200);
        list.add(300);
        // 遍历
        for (Integer integer : list) {
            System.out.println(integer);
        }

        Map<String,Object> map = new HashMap<>();
        map.put("name","张三");
        map.put("age",18);
        map.put("sex","男");
        // 遍历
        Set<Map.Entry<String, Object>> entries = map.entrySet();
        for (Map.Entry<String, Object> entry : entries) {
            System.out.println(entry.getKey() + "=" + entry.getValue());
        }
    }

    /**
     * 泛型类
     */
    @Test
    public void test02() {
        User<String,Integer> user = new User<>();
        user.setUsername("张三");
        user.setPassword(123456);
    }
}

class User<T,T1>{
    private T username;
    private T1 password;

    public T getUsername() {
        return username;
    }

    public void setUsername(T username) {
        this.username = username;
    }

    public T1 getPassword() {
        return password;
    }

    public void setPassword(T1 password) {
        this.password = password;
    }
}

























